﻿/**
 过滤非法视屏
*/
(function(E, $){
E.addFilter('video', {
	replace: function( dom ){
		if(typeof dom !='object' 
			|| !dom.body 
			|| !(E.get('option').video_whiteList instanceof Array)
		){
			return dom;
		}
		var video_urls = E.get('option').video_whiteList.slice(0),//复制一份合法的域名
			videos = E.$('object,embed'),
			reg = null,
			del = true, 
			tmp = '', 
			obj = null ,
			item='';
			
		//把所有网址都转为正则表达式，同时去掉http://
		video_urls = video_urls.join('|').toUpperCase().replace(/http:\/\//ig, '').replace(/\./g,'\\\.');
		video_urls = '('+ video_urls + ')$';
		reg = new RegExp(video_urls,'i');
		videos.each(function(){
			obj = $(this);
			tmp = obj.attr('src');
			if(tmp.length){
				tmp = tmp.replace('http://','').replace(/(\?|#)/g,'/').split('/');//去掉src的http://
				if(tmp && tmp.length > 0){
					if(reg.test(tmp[0])){
						del = false;
					}
				}
			}
			if(del){
				obj.remove();
			}
			del = true;
		});
	}
});

})(jQEditor, jQuery);